#ifndef CORE_H
#define CORE_H

#define MAX_SHEETS 256
#define MAX_CHANNELS 256

#include <string>
#include <vector>
#include <map>

class Filesystem;
class Sheet;

class SheetCallback
{
public:
	virtual void sheetCreated(Sheet* newSheet, int sid)=0;
	virtual void sheetDeleted(Sheet* sheetToBeDeleted, int sid)=0;
};

class GlobalObject
{
public:
	virtual std::string getClassName()=0;
	virtual void updateFromUM(double dt)=0;
};

class Console
{
public:
	virtual void sendMessage(const std::string& message)=0;
	virtual std::vector<std::string> receiveMessages()=0;
};

class ConHookStub
{
public:
	Console* hook;
	int chan;
};

class Core
{
public:
	static const std::string DEFAULT_PATH;
	static const int CHAN_ANY;
	static const int SHEET_GLOBAL;
	
	Core();
    Core(std::string localPath);
    Core(int argc, char** argv);
    Core(std::string localPath, int argc, char** argv);
	int createSheet(std::string masterClass = "");
	bool deleteSheet(int sheetId);
	Sheet* getSheet(int sheetId);
	void updateAllSheets(double dt);
	void updateSheet(int sheetId, double dt);
	void updateGlobalObjects(double dt);
	void addCallback(SheetCallback* cb);
	void addGlobalObject(GlobalObject* go, std::string oname);
	int addConsole(Console* hook, int sheet, int chan = -1);
	void removeConsole(Console* hook);
	void sendGlobalConMessage(std::string& msg);
	bool quitSignal();
	void quit();
	std::vector<std::string> getSysArg(const std::string& name);
	std::vector<std::string> getSysArgContexts();
	GlobalObject* getGlobalObject(std::string oname);
	Filesystem* getFs();
	~Core();
private:
	Sheet* _sheets[MAX_SHEETS];
	std::vector<SheetCallback*> _callbacks;
	std::map<std::string,GlobalObject*> _gObjMap;
	std::vector<GlobalObject*> _gObjList;
	std::vector<Console*> _globalConsoles;
	std::map<std::string, std::vector<std::string> > _sysargs;
	std::vector<std::string> _sysargc;
	Filesystem* _fs;
	bool _quitSignal;
    void init(std::string localPath, int argc, char** argv);
};

#endif
